//
//  ViewController.m
//  AutoLayoutVFL
//
//  Created by student on 16/3/2.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self test1];
}

- (void)test1
{
    UIView *blueview = [[UIView alloc] init];
    blueview.backgroundColor = [UIColor blueColor];
    blueview.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:blueview];
    
    UIView *redview = [[UIView alloc] init];
    redview.backgroundColor = [UIColor redColor];
    redview.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:redview];
    
    
    //水平方向
    NSNumber *margin = @20;
    NSString *vfl1 = @"H:|-margin-[blueview]-margin-[redview(==blueview)]-margin-|";
    NSDictionary *viewDict1 = NSDictionaryOfVariableBindings(blueview,redview);
    NSDictionary *metrics1 = NSDictionaryOfVariableBindings(margin);
    NSArray *constraints1 = [NSLayoutConstraint constraintsWithVisualFormat:vfl1
                                                                    options:kNilOptions
                                                                    metrics:metrics1
                                                                      views:viewDict1];
    [self.view addConstraints:constraints1];
    
    //blueview的垂直方向
    NSNumber *height = @40;
    NSString *vfl2 = @"V:|-[blueview(height)]-margin-|";
    NSDictionary *viewDict2 = NSDictionaryOfVariableBindings(blueview);
    NSDictionary *metrics2 = NSDictionaryOfVariableBindings(margin,height);
    NSArray *constraints2 = [NSLayoutConstraint constraintsWithVisualFormat:vfl2
                                                                    options:kNilOptions
                                                                    metrics:metrics2
                                                                      views:viewDict2];
    [self.view addConstraints:constraints2];
    
    //redview的垂直方向
    NSString *vfl3 = @"V:|-[redview(height)]-margin-|";
    NSDictionary *viewDict3 = NSDictionaryOfVariableBindings(redview);
    NSDictionary *metrics3 = NSDictionaryOfVariableBindings(margin,height);
    NSArray *constraints3 = [NSLayoutConstraint constraintsWithVisualFormat:vfl3
                                                                    options:kNilOptions
                                                                    metrics:metrics3
                                                                      views:viewDict3];
    [self.view addConstraints:constraints3];
}

@end
